#pragma once

#include <cstdlib>
#include <iostream>

// Memory checking utilities (simplified implementation)

// Memory allocation tracking
class MemoryTracker {
public:
    static MemoryTracker& Instance();
    
    void* Allocate(size_t size);
    void Deallocate(void* ptr);
    
    size_t GetTotalAllocated() const { return total_allocated; }
    size_t GetAllocationCount() const { return allocation_count; }
    
    void DumpLeaks();
    
private:
    MemoryTracker() = default;
    ~MemoryTracker() = default;
    
    size_t total_allocated = 0;
    size_t allocation_count = 0;
    
    // For real implementation, we'd track allocations here
};

// Memory allocation wrappers
inline void* DebugMalloc(size_t size) {
    return MemoryTracker::Instance().Allocate(size);
}

inline void DebugFree(void* ptr) {
    MemoryTracker::Instance().Deallocate(ptr);
}

// Memory checking macros
#define MEMCHECK_INIT()
#define MEMCHECK_CHECK()
#define MEMCHECK_DUMP_LEAKS() MemoryTracker::Instance().DumpLeaks()

// For now, just use standard malloc/free
inline void* MemoryTracker::Allocate(size_t size) {
    void* ptr = malloc(size);
    if (ptr) {
        total_allocated += size;
        allocation_count++;
    }
    return ptr;
}

inline void MemoryTracker::Deallocate(void* ptr) {
    if (ptr) {
        free(ptr);
        allocation_count--;
    }
}

inline void MemoryTracker::DumpLeaks() {
    if (allocation_count > 0) {
        std::cout << "Memory leak detected: " << allocation_count 
                  << " allocations not freed" << std::endl;
    }
}